<?php

/**
 * 短信验证码接口
 */
class SmsController extends ControllerBase {

    /**
     * 发送短信验证码 [GET]
     * @param int $phone 电话号码
     * 接口请求地址：/sms/send/
     * 返回结果：{"retcode":0,"retmsg":"正确的验证码"}
     */
    public function sendAction() {
        $phone = $this->request->get('phone');
        if (is_numeric($phone)) {
            $validCode = rand(100000, 599999);
            $content = sprintf("您的验证码是：%s，12小时内有效。真房买卖APP欢迎您的使用～", $validCode);
            if (Sms::sendSmsToWebchinese($phone, $content)) {
                $this->echoMsg(0, $validCode);
            } else {
                $this->echoErrcode(ErrorCode::$ERR_SMSERROR_FAILED);
            }
        } else {
            $this->echoErrcode(ErrorCode::$ERR_SMSERROR_PARAM);
        }
    }

}
